﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace Пятн
{
    public class Game1
    {
        public Form2 form;
        public int[] pos;

        public Game1(Form2 f2)
        {
            form = f2;
        } 

        public void Location1()
        {
            form.pictureBox1.Location = new Point(35, 41);
            form.pictureBox2.Location = new Point(141, 41);
            form.pictureBox3.Location = new Point(247, 41);
            form.pictureBox4.Location = new Point(35, 147);
            form.pictureBox5.Location = new Point(141, 147);
            form.pictureBox6.Location = new Point(247, 147);
            form.pictureBox7.Location = new Point(35, 253);
            form.pictureBox8.Location = new Point(141, 253);
            form.pictureBox9.Location = new Point(247, 253);
        }

        public void Location2()
        {
            form.pictureBox1.Location = new Point(41, 47);
            form.pictureBox2.Location = new Point(141, 47);
            form.pictureBox3.Location = new Point(241, 47);
            form.pictureBox4.Location = new Point(41, 147);
            form.pictureBox5.Location = new Point(141, 147);
            form.pictureBox6.Location = new Point(241, 147);
            form.pictureBox7.Location = new Point(41, 247);
            form.pictureBox8.Location = new Point(141, 247);
            form.pictureBox9.Location = new Point(241, 247);
        }
        
        public bool Analiz()
        {
            
            int i;
            for (i = 0; i < pos.Length; i++)
            {
                if (!(pos[i] == i + 1))
                    break;
            }
            if (i == pos.Length-1 && pos[pos.Length-1] == 0)
            {
                return true;
            }
            return false;
        }

        public void Move(int from, int clear)
        {
           switch(from)
           {
               case 1:
                   {
                       switch (clear)
                       {
                           case 2:
                               {
                                   form.pictureBox2.Image = form.pictureBox1.Image;
                                   form.pictureBox1.Image = form.empty.Image;
                                   form.clear = 1;
                                   pos[1] = pos[0];
                                   pos[0] = 0;
                               }
                               break;
                           case 4:
                               {
                                   form.pictureBox4.Image = form.pictureBox1.Image;
                                   form.pictureBox1.Image = form.empty.Image;
                                   form.clear = 1;
                                   pos[3] = pos[0];
                                   pos[0] = 0;
                               }
                               break;
                       }
                   }
                   break;
               case 2:
                 {
                     switch (clear)
                     {
                         case 1:
                             {
                                 form.pictureBox1.Image = form.pictureBox2.Image;
                                 form.pictureBox2.Image = form.empty.Image;
                                 form.clear = 2;
                                 pos[0] = pos[1];
                                 pos[1] = 0;
                             }
                             break;
                         case 5:
                             {
                                 form.pictureBox5.Image = form.pictureBox2.Image;
                                 form.pictureBox2.Image = form.empty.Image;
                                 form.clear = 2;
                                 pos[4] = pos[1];
                                 pos[1] = 0;
                             }
                             break;
                         case 3:
                             {
                                 form.pictureBox3.Image = form.pictureBox2.Image;
                                 form.pictureBox2.Image = form.empty.Image;
                                 form.clear = 2;
                                 pos[2] = pos[1];
                                 pos[1] = 0;
                             }
                             break;
                     }
                 }
                 break;
              case 3:
                 {
                     switch (clear)
                     {
                         case 2:
                             {
                                 form.pictureBox2.Image = form.pictureBox3.Image;
                                 form.pictureBox3.Image = form.empty.Image;
                                 form.clear = 3;
                                 pos[1] = pos[2];
                                 pos[2] = 0;
                             }
                             break;
                         case 6:
                             {
                                 form.pictureBox6.Image = form.pictureBox3.Image;
                                 form.pictureBox3.Image = form.empty.Image;
                                 form.clear = 3;
                                 pos[5] = pos[2];
                                 pos[2] = 0;
                             }
                             break;
                     }
                 }
                 break;
              case 4:
                 {
                     switch (clear)
                     {
                         case 1:
                             {
                                 form.pictureBox1.Image = form.pictureBox4.Image;
                                 form.pictureBox4.Image = form.empty.Image;
                                 form.clear = 4;
                                 pos[0] = pos[3];
                                 pos[3] = 0;
                             }
                             break;
                         case 5:
                             {
                                 form.pictureBox5.Image = form.pictureBox4.Image;
                                 form.pictureBox4.Image = form.empty.Image;
                                 form.clear = 4;
                                 pos[4] = pos[3];
                                 pos[3] = 0;
                             }
                             break;
                         case 7:
                             {
                                 form.pictureBox7.Image = form.pictureBox4.Image;
                                 form.pictureBox4.Image = form.empty.Image;
                                 form.clear = 4;
                                 pos[6] = pos[3];
                                 pos[3] = 0;
                             }
                             break;
                     }
                 }
                 break;
              case 5:
                 {
                     switch (clear)
                     {
                         case 2:
                             {
                                 form.pictureBox2.Image = form.pictureBox5.Image;
                                 form.pictureBox5.Image = form.empty.Image;
                                 form.clear = 5;
                                 pos[1] = pos[4];
                                 pos[4] = 0;
                             }
                             break;
                         case 4:
                             {
                                 form.pictureBox4.Image = form.pictureBox5.Image;
                                 form.pictureBox5.Image = form.empty.Image;
                                 form.clear = 5;
                                 pos[3] = pos[4];
                                 pos[4] = 0;
                             }
                             break;
                         case 6:
                             {
                                 form.pictureBox6.Image = form.pictureBox5.Image;
                                 form.pictureBox5.Image = form.empty.Image;
                                 form.clear = 5;
                                 pos[5] = pos[4];
                                 pos[4] = 0;
                             }
                             break;
                         case 8:
                             {
                                 form.pictureBox8.Image = form.pictureBox5.Image;
                                 form.pictureBox5.Image = form.empty.Image;
                                 form.clear = 5;
                                 pos[7] = pos[4];
                                 pos[4] = 0;
                             }
                             break;
                     }
                 }
                 break;
              case 6:
                 {
                     switch (clear)
                     {
                         case 3:
                             {
                                 form.pictureBox3.Image = form.pictureBox6.Image;
                                 form.pictureBox6.Image = form.empty.Image;
                                 form.clear = 6;
                                 pos[2] = pos[5];
                                 pos[5] = 0;
                             }
                             break;
                         case 5:
                             {
                                 form.pictureBox5.Image = form.pictureBox6.Image;
                                 form.pictureBox6.Image = form.empty.Image;
                                 form.clear = 6;
                                 pos[4] = pos[5];
                                 pos[5] = 0;
                             }
                             break;
                         case 9:
                             {
                                 form.pictureBox9.Image = form.pictureBox6.Image;
                                 form.pictureBox6.Image = form.empty.Image;
                                 form.clear = 6;
                                 pos[8] = pos[5];
                                 pos[5] = 0;
                             }
                             break;
                     }
                 }
                 break;
              case 7:
                 {
                     switch (clear)
                     {
                         case 4:
                             {
                                 form.pictureBox4.Image = form.pictureBox7.Image;
                                 form.pictureBox7.Image = form.empty.Image;
                                 form.clear = 7;
                                 pos[3] = pos[6];
                                 pos[6] = 0;
                             }
                             break;
                         case 8:
                             {
                                 form.pictureBox8.Image = form.pictureBox7.Image;
                                 form.pictureBox7.Image = form.empty.Image;
                                 form.clear = 7;
                                 pos[7] = pos[6];
                                 pos[6] = 0;
                             }
                             break;
                     }
                 }
                 break;
              case 8:
                 {
                     switch (clear)
                     {
                         case 5:
                             {
                                 form.pictureBox5.Image = form.pictureBox8.Image;
                                 form.pictureBox8.Image = form.empty.Image;
                                 form.clear = 8;
                                 pos[4] = pos[7];
                                 pos[7] = 0;
                             }
                             break;
                         case 7:
                             {
                                 form.pictureBox7.Image = form.pictureBox8.Image;
                                 form.pictureBox8.Image = form.empty.Image;
                                 form.clear = 8;
                                 pos[6] = pos[7];
                                 pos[7] = 0;
                             }
                             break;
                         case 9:
                             {

                                 form.pictureBox9.Image = form.pictureBox8.Image;
                                 form.pictureBox8.Image = form.empty.Image;
                                 form.clear = 8;
                                 pos[8] = pos[7];
                                 pos[7] = 0;
                             }
                             break;
                     }
                 }
                 break;
              case 9:
                 {
                     switch (clear)
                     {
                         case 6:
                             {
                                 form.pictureBox6.Image = form.pictureBox9.Image;
                                 form.pictureBox9.Image = form.empty.Image;
                                 form.clear = 9;
                                 pos[5] = pos[8];
                                 pos[8] = 0;
                             }
                             break;
                         case 8:
                             {
                                 form.pictureBox8.Image = form.pictureBox9.Image;
                                 form.pictureBox9.Image = form.empty.Image;
                                 form.clear = 9;
                                 pos[7] = pos[8];
                                 pos[8] = 0;
                             }
                             break;
                     }
                 }
                 break;

           }
        }
    }
}
